home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / asm / demos / 3dstars_type1 / 3dstarsjoy.s < prev    next >
Text File  |  1980-01-06  |  12KB  |  598 lines

  1.  
  2. *************** 3D Starfields..
  3.  
  4. PlaneHeight    = 255
  5. PlaneWidth    = 40
  6. PlaneLen    = PlaneHeight*PlaneWidth
  7. PL        = PlaneLen
  8. PlaneBLTSIZE    = 3*PlaneHeight*64+(PlaneWidth/2)
  9. MaxTiefe    = $2000
  10. StarCount    = 335
  11. X        = 160
  12. Y        = 128
  13. Z        = 256
  14. ClipX        = 319
  15. ClipY        = 254
  16. JoySpeed    = 5
  17.  
  18.         section    chippy,code_c
  19.         
  20. WAITBLITT:    MACRO
  21.         btst    #6,$02(a6)
  22. .\@:        btst    #6,$02(a6)
  23.         bne.s    .\@
  24.         ENDM
  25.  
  26.         incdir    'scene1:coding/asm/demos/exsyslib/'
  27.         include    'include/hardware/exsys_takeover.s' ;1st codeline!
  28.  
  29.         bsr    RandomStars
  30.         bsr.s    CalcTab
  31.         bsr.w    MakePerspTab
  32.  
  33.         lea    (_Custom).l,a6        ; custom base address in a6
  34.         move.w    #$7fff,intena(a6)    ; turn off intena
  35.         move.l  #Copperlist,cop1lch(a6)    ; install custom copperlist
  36.         move.w    d0,copjmp1(a6)        ; clear second copperlist
  37.         move.w    #$c020,intena(a6)    ; return INTENA:
  38.         move.w  #$87c0,dmacon(a6)    ; return DMA:Cop/Blit/Sprite
  39.  
  40. ***************************************************
  41. *** Main Loop                    ***
  42. ***************************************************
  43.  
  44. Main:        cmp.b    #255,$dff006
  45.         bne.s    Main
  46.  
  47.         bsr    ClearPlane
  48.         bsr    JoyControl
  49.         bsr.w    New3DStars
  50.         lea    $dff000,a6
  51.         bsr    ChangePlanes
  52.  
  53.         btst    #6,$bfe001
  54.         bne.s    Main
  55.         rts
  56.  
  57. ***************************************************
  58. *** Build Y Table                ***
  59. ***************************************************
  60.  
  61. CalcTab:    lea    YTab(pc),a0
  62.         moveq    #0,d0
  63.         move.w    #PlaneHeight-1,d7
  64. .Loop:        move.w    d0,(a0)+
  65.         add.w    #PlaneWidth,d0
  66.         dbra    d7,.Loop
  67.         rts
  68.  
  69. ***************************************************
  70. *** Build Division Table            ***
  71. ***************************************************
  72.  
  73. MakePerspTab:    lea    PerspTab,a1
  74.         move.w    #Z,d0
  75.         add.w    d0,a1
  76.         add.w    d0,a1
  77.         move.w    #Z,d2
  78.         mulu    #$7fff,d2
  79. .Loop:        move.l    d2,d1
  80.         divu    d0,d1
  81.         move.w    d1,(a1)+
  82.         addq.w    #1,d0
  83.         cmp.w    #MaxTiefe,d0
  84.         bne.s    .Loop
  85.         rts
  86.  
  87. ***************************************************
  88. *** Random Stars                ***
  89. ***************************************************
  90.  
  91. RandomStars:    lea    StarDatas,a0
  92.         move.w    #$1fff,d3
  93.         move.w    #StarCount-1,d7
  94.  
  95. .Loop:        bsr.s    GetWord            ;X Word
  96.         add.w    #X,d2
  97.         and.w    d3,d2
  98.         sub.w    #X,d2
  99.         move.w    d2,(a0)+
  100.         bsr.s    GetWord            ;Y Word
  101.         add.w    #Y,d2
  102.         and.w    d3,d2
  103.         sub.w    #Y,d2
  104.         move.w    d2,(a0)+
  105.         bsr.s    GetWord            ;Z Word
  106.         add.w    #Z,d2
  107.         and.w    d3,d2
  108.         sub.w    #Z,d2
  109.         move.w    d2,(a0)+
  110.         dbf    d7,.Loop
  111.         rts
  112.  
  113. GetWord:    bsr.s    GetByte
  114.         move.b    d0,d2
  115.         lsl.w    #8,d2
  116.         bsr.s    GetByte
  117.         move.b    d0,d2
  118.         rts
  119.  
  120. GetByte:    move.b    $dff007,d0
  121.         move.b    $bfd800,d1
  122.         eor.b    d1,d0
  123.         moveq    #0,d1
  124.         move.b    d0,d1
  125.         ror.b    #1,d1
  126. .loop:        dbf    d1,.loop
  127.         rts
  128.  
  129. ***************************************************
  130. *** 3D Star Routine                ***
  131. ***************************************************
  132.  
  133. New3DStars:    move.w    #StarCount-1,d7        ;64 Stars
  134.         lea    StarDatas,a0        ;Ptr StarDatas
  135.         lea    PerspTab,a1        ;Projection Table
  136.         movem.w    XAdd(pc),a4-a6        ;Put coordinate adds in regs
  137.         move.w    #ClipX,a3        ;Clipping constante
  138.         move.w    #ClipY,d5
  139.         move.w    #$1fff,d3
  140.         move.w    #$1000,d4        ;middle value
  141.         add.w    d4,a4            ;+x add
  142.         add.w    d4,a5            ;+y add
  143.  
  144. .Loop:        movem.w    (a0),d0-d2        ;Get coordinate
  145.  
  146.         add.w    a4,d0            ;add middle and de/increase x
  147.         and.w    d3,d0            ;check overflow
  148.         sub.w    d4,d0            ;sub middle
  149.         add.w    a5,d1            ;add middle and de/increase y
  150.         and.w    d3,d1            ;check overflow
  151.         sub.w    d4,d1            ;sub middle
  152.         add.w    a6,d2            ;de/increase z
  153.         and.w    d3,d2            ;check overflow
  154.  
  155.         movem.w    d0-d2,(a0)        ;save coords
  156.         addq.w    #6,a0            ;(there is no movem.w d0,(a0)+)
  157.  
  158. ; >--- Projection, vlipping und plot
  159. ;/
  160.  
  161. .SetStar:    cmp.w    #Z,d2            ;z<d2?
  162.         blt.s    .Next            ;-> Next star
  163.         add.w    d2,d2            ;Z*2
  164.         move.w    (a1,d2.w),d6        ;Projektionswert holen
  165.  
  166. ;It's very important to do the following commands in this order. It's very
  167. ;stupid of you do it like this:
  168. ;            muls    d6,d0
  169. ;            muls    d6,d1
  170. ;            swap    d0
  171. ;            swap    d1
  172. ;            etc...
  173. ;Ok, the source looks better but there is one BIG disadvantage!!! If e.g.
  174. ;the x value isn't in the screen you don't have the plot this pixel. But
  175. ;if the pixel musn't be plot it is really stupid to check/calculate the
  176. ;y value!!! Understood??? The following routine is much better! It first
  177. ;checks if the x value is within the screen. If it is, the y value will be
  178. ;calculated. If not, the y value won't be calculated (We can't save the
  179. ;unneccessary 'muls d6,d1' in this case!!!
  180.  
  181.         muls    d6,d0            ;projection
  182.         swap    d0            ;
  183.         add.w    #X,d0            ;X middle of screen (160)
  184.         cmp.w    a3,d0            ;a3=ClipX (Clipping)
  185.         bhi.s    .Next            ;Don't plot
  186.  
  187.         muls    d6,d1            ;projection
  188.         swap    d1
  189.         add.w    #Y,d1            ;Y middle of screen (128)
  190.         cmp.w    d5,d1            ;a4=ClipY
  191.         bhi.s    .Next            ;Don't plot
  192.  
  193.         move.l    WorkPlane(pc),a2    ;plot pixel
  194.         move.w    d0,d6
  195.         lsr.w    #3,d6
  196.         add.w    d6,a2
  197.         add.w    d1,d1
  198.         add.w    YTab(pc,d1.w),a2
  199.         not.w    d0
  200.  
  201.         rol.w    #6,d2            ;get color
  202.         and.w    #$e,d2
  203.         move.w    .JT(pc,d2.w),d2
  204.         jmp    .JT(pc,d2.w)
  205.  
  206. .JT:        dc.w    .r6-.JT,.r6-.JT,.r5-.JT,.r4-.JT
  207.         dc.w    .r3-.JT,.r2-.JT,.r1-.JT,.r0-.JT
  208.  
  209. .r0:        bset    d0,(a2)            ;plot routines...
  210. .next:        dbf    d7,.Loop
  211.         rts
  212. .r1:        bset    d0,PL(a2)
  213.         dbf    d7,.Loop
  214.         rts
  215. .r2:        bset    d0,(a2)
  216.         bset    d0,PL(a2)
  217.         dbf    d7,.Loop
  218.         rts
  219. .r3:        bset    d0,PL*2(a2)
  220.         dbf    d7,.Loop
  221.         rts
  222. .r4:        bset    d0,(a2)
  223.         bset    d0,PL*2(a2)
  224.         dbf    d7,.Loop
  225.         rts
  226. .r5:        bset    d0,PL(a2)
  227.         bset    d0,PL*2(a2)
  228.         dbf    d7,.Loop
  229.         rts
  230. .r6:        bset    d0,(a2)
  231.         bset    d0,PL(a2)
  232.         bset    d0,PL*2(a2)
  233.         dbf    d7,.Loop
  234.         rts
  235.  
  236. XAdd:        dc.w    0
  237. YAdd:        dc.w    0
  238. ZAdd:        dc.w    -100
  239.  
  240. YTab:        ds.w    PlaneHeight
  241.  
  242. ***************************************************
  243. *** Joystick Control                ***
  244. ***************************************************
  245.  
  246. JoyControl:    lea    XAdd(pc),a0
  247.         lea    ZAdd(pc),a1
  248.         tst.b    $bfe001            ;Y or Z?
  249.         bpl.s    .Pressed        ;Z-> Pressed
  250.  
  251.         lea    YAdd(pc),a1        ;otherwise Y
  252.  
  253. .Pressed:    move.w    $0c(a6),d0
  254.         btst    #1,d0
  255.         beq.s    .TstLinks
  256.         subq.w    #JoySpeed,(a0)
  257.         bra.s    .DoY
  258. .TstLinks:    btst    #9,d0
  259.         beq.s    .DoY
  260.         addq.w    #JoySpeed,(a0)
  261.  
  262. .DoY:        move.w    d0,d1
  263.         lsr.w    #1,d1
  264.         eor.w    d0,d1
  265.         btst    #0,d1
  266.         beq.s    .TstVorne
  267.         addq.w    #JoySpeed,(a1)
  268.         bra.s    .Exit
  269. .TstVorne:    btst    #8,d1
  270.         beq.s    .Exit
  271.         subq.w    #JoySpeed,(a1)
  272. .Exit:        rts
  273.  
  274. ***************************************************
  275. *** clear DelPlane                ***
  276. ***************************************************
  277.  
  278. ClearPlane:    WAITBLITT
  279.  
  280.         move.l    DelPlane(pc),$54(a6)
  281.         clr.w    $66(a6)
  282.         move.l    #$01000000,$40(a6)
  283.         move.w    #PlaneBLTSIZE,$58(a6)
  284.         rts
  285.  
  286. ***************************************************
  287. *** Tripple Buffering                ***
  288. ***************************************************
  289.  
  290. ChangePlanes:    lea    Plane(pc),a0
  291.         movem.l    (a0),d0-d2
  292.         exg    d0,d1
  293.         exg    d1,d2
  294.         movem.l    d0-d2,(a0)
  295.         lea    PlanePtrs(pc),a0
  296.         move.w    d0,6(a0)
  297.         swap    d0
  298.         move.w    d0,2(a0)
  299.         swap    d0
  300.         add.l    #PlaneLen,d0
  301.         move.w    d0,6+8(a0)
  302.         swap    d0
  303.         move.w    d0,2+8(a0)
  304.         swap    d0
  305.         add.l    #PlaneLen,d0
  306.         move.w    d0,6+16(a0)
  307.         swap    d0
  308.         move.w    d0,2+16(a0)
  309.         swap    d0
  310.         rts
  311.  
  312. Plane:        dc.l    Plane1
  313. WorkPlane:    dc.l    Plane2
  314. DelPlane:    dc.l    Plane3
  315.  
  316. ***************************************************
  317. *** Datas                    ***
  318. ***************************************************
  319.  
  320. * Try Germany/0+$4498a7c!!! (Ask for Karsten!)
  321.  
  322. Copperlist:    dc.l    $01200000,$01220000,$01240000,$01260000
  323.         dc.l    $01280000,$012a0000,$012c0000,$012e0000
  324.         dc.l    $01300000,$01320000,$01340000,$01360000
  325.         dc.l    $01380000,$013a0000,$013c0000,$013e0000
  326.  
  327.         dc.l    $008e2c81,$00902bc1,$00920038,$009400d0
  328.         dc.l    $01020000,$01040000,$01080000,$010a0000
  329.         dc.l    $01000200,$01060000,$01fc0000
  330.  
  331. PlanePtrs:    dc.l    $00e00000,$00e20000,$00e40000,$00e60000
  332.         dc.l    $00e80000,$00ea0000
  333.         dc.l    $01003200
  334.  
  335.         dc.l    $01800000,$01820333,$01840555,$01860777
  336.         dc.l    $01880999,$018a0bbb,$018c0ddd,$018e0fff
  337.         dc.l    -2
  338.  
  339.         section    b,bss_c
  340. Plane1:        ds.b    PlaneLen*3
  341. Plane2:        ds.b    PlaneLen*3
  342. Plane3:        ds.b    PlaneLen*3
  343. PerspTab:    ds.w    MaxTiefe
  344. StarDatas:    ds.w    StarCount*3
  345.  
  346. Level3Vector    equ $6c
  347. SysCop1        equ $26
  348. _ciaa:        equ $bfe001
  349. _ciab:        equ $bfd000
  350. left        equ 6
  351.  
  352. _custom:    equ $dff000
  353. bltddat:    equ $000
  354. dmaconr:    equ $002
  355. vposr:        equ $004
  356. vhposr:        equ $006
  357. dskdatr:    equ $008
  358. joy0dat:    equ $00a
  359. joy1dat:    equ $00c
  360. clxdat:        equ $00e
  361. adkconr:    equ $010
  362. pot0dat:    equ $012
  363. pot1dat:    equ $014
  364. potgor:        equ $016
  365. serdatr:    equ $018
  366. dskbytr:    equ $01a
  367. intenar:    equ $01c
  368. intreqr:    equ $01e
  369. dskpth:        equ $020
  370. dskptl:        equ $022
  371. dsklen:        equ $024
  372. dskdat:        equ $026
  373. refptr:        equ $028
  374. vposw:        equ $02a
  375. vhposw:        equ $02c
  376. copcon:        equ $02e
  377. serdat:        equ $030
  378. serper:        equ $032
  379. potgo:        equ $034
  380. joytest:    equ $036
  381. strequ:        equ $038
  382. strvbl:        equ $03a
  383. strhor:        equ $03c
  384. strlong:    equ $03e
  385. bltcon0:    equ $040
  386. bltcon1:    equ $042
  387. bltafwm:    equ $044
  388. bltalwm:    equ $046
  389. bltcpth:    equ $048
  390. bltcptl:    equ $04a
  391. bltbpth:    equ $04c
  392. bltbptl:    equ $04e
  393. bltapth:    equ $050
  394. bltaptl:    equ $052
  395. bltdpth:    equ $054
  396. bltdptl:    equ $056
  397. bltsize:    equ $058
  398. bltcmod:    equ $060
  399. bltbmod:    equ $062
  400. bltamod:    equ $064
  401. bltdmod:    equ $066
  402. bltcdat:    equ $070
  403. bltbdat:    equ $072
  404. bltadat:    equ $074
  405. dsksync:    equ $07e
  406. cop1lch:    equ $080
  407. cop1lcl:    equ $082
  408. cop2lch:    equ $084
  409. cop2lcl:    equ $086
  410. copjmp1:    equ $088
  411. copjmp2:    equ $08a
  412. copins:        equ $08c
  413. diwstrt:    equ $08e
  414. diwstop:    equ $090
  415. ddfstrt:    equ $092
  416. ddfstop:    equ $094
  417. dmacon:        equ $096
  418. clxcon:        equ $098
  419. intena:        equ $09a
  420. intreq:        equ $09c
  421. adkcon:        equ $09e
  422. aud0pth:    equ $0a0
  423. aud0ptl:    equ $0a2
  424. aud0len:    equ $0a4
  425. aud0per:    equ $0a6
  426. aud0vol:    equ $0a8
  427. aud0dat:    equ $0aa
  428. aud1pth:    equ $0b0
  429. aud1ptl:    equ $0b2
  430. aud1len:    equ $0b4
  431. aud1per:    equ $0b6
  432. aud1vol:    equ $0b8
  433. aud1dat:    equ $0ba
  434. aud2pth:    equ $0c0
  435. aud2ptl:    equ $0c2
  436. aud2len:    equ $0c4
  437. aud2per:    equ $0c6
  438. aud2vol:    equ $0c8
  439. aud2dat:    equ $0ca
  440. aud3pth:    equ $0d0
  441. aud3ptl:    equ $0d2
  442. aud3len:    equ $0d4
  443. aud3per:    equ $0d6
  444. aud3vol:    equ $0d8
  445. aud3dat:    equ $0da
  446. bpl1pth:    equ $0e0
  447. bpl1ptl:    equ $0e2
  448. bpl2pth:    equ $0e4
  449. bpl2ptl:    equ $0e6
  450. bpl3pth:    equ $0e8
  451. bpl3ptl:    equ $0ea
  452. bpl4pth:    equ $0ec
  453. bpl4ptl:    equ $0ee
  454. bpl5pth:    equ $0f0
  455. bpl5ptl:    equ $0f2
  456. bpl6pth:    equ $0f4
  457. bpl6ptl:    equ $0f6
  458. bplcon0:    equ $100
  459. bplcon1:    equ $102
  460. bplcon2:    equ $104
  461. bpl1mod:    equ $108
  462. bpl2mod:    equ $10a
  463. bpl1dat:    equ $110
  464. bpl2dat:    equ $112
  465. bpl3dat:    equ $114
  466. bpl4dat:    equ $116
  467. bpl5dat:    equ $118
  468. bpl6dat:    equ $11a
  469. spr0pth:    equ $120
  470. spr0ptl:    equ $122
  471. spr1pth:    equ $124
  472. spr1ptl:    equ $126
  473. spr2pth:    equ $128
  474. spr2ptl:    equ $12a
  475. spr3pth:    equ $12c
  476. spr3ptl:    equ $12e
  477. spr4pth:    equ $130
  478. spr4ptl:    equ $132
  479. spr5pth:    equ $134
  480. spr5ptl:    equ $136
  481. spr6pth:    equ $138
  482. spr6ptl:    equ $13a
  483. spr7pth:    equ $13c
  484. spr7ptl:    equ $13e
  485. spr0pos:    equ $140
  486. spr0ctl:    equ $142
  487. spr0data:    equ $144
  488. spr0datb:    equ $146
  489. spr1pos:    equ $148
  490. spr1ctl:    equ $14a
  491. spr1data:    equ $14c
  492. spr1datb:    equ $14e
  493. spr2pos:    equ $150
  494. spr2ctl:    equ $152
  495. spr2data:    equ $154
  496. spr2datb:    equ $156
  497. spr3pos:    equ $158
  498. spr3ctl:    equ $15a
  499. spr3data:    equ $15c
  500. spr3datb:    equ $15e
  501. spr4pos:    equ $160
  502. spr4ctl:    equ $162
  503. spr4data:    equ $164
  504. spr4datb:    equ $166
  505. spr5pos:    equ $168
  506. spr5ctl:    equ $16a
  507. spr5data:    equ $16c
  508. spr5datb:    equ $16e
  509. spr6pos:    equ $170
  510. spr6ctl:    equ $172
  511. spr6data:    equ $174
  512. spr6datb:    equ $176
  513. spr7pos:    equ $178
  514. spr7ctl:    equ $17a
  515. spr7data:    equ $17c
  516. spr7datb:    equ $17e
  517. color00:    equ $180
  518. color01:    equ $182
  519. color02:    equ $184
  520. color03:    equ $186
  521. color04:    equ $188
  522. color05:    equ $18a
  523. color06:    equ $18c
  524. color07:    equ $18e
  525. color08:    equ $190
  526. color09:    equ $192
  527. color10:    equ $194
  528. color11:    equ $196
  529. color12:    equ $198
  530. color13:    equ $19a
  531. color14:    equ $19c
  532. color15:    equ $19e
  533. color16:    equ $1a0
  534. color17:    equ $1a2
  535. color18:    equ $1a4
  536. color19:    equ $1a6
  537. color20:    equ $1a8
  538. color21:    equ $1aa
  539. color22:    equ $1ac
  540. color23:    equ $1ae
  541. color24:    equ $1b0
  542. color25:    equ $1b2
  543. color26:    equ $1b4
  544. color27:    equ $1b6
  545. color28:    equ $1b8
  546. color29:    equ $1ba
  547. color30:    equ $1bc
  548. color31:    equ $1be
  549. open:        equ -30
  550. close:        equ -36
  551. read:        equ -42
  552. write:        equ -48
  553. input:        equ -54
  554. output:        equ -60
  555. seek:        equ -66
  556. deletefile:    equ -72
  557. rename:        equ -78
  558. lock:        equ -84
  559. unlock:        equ -90
  560. duplock:    equ -96
  561. examine:    equ -102
  562. exnext:        equ -108
  563. info:        equ -114
  564. createdir:    equ -120
  565. currentdir:    equ -126
  566. ioErr:        equ -132
  567. CreateProc:    equ -138
  568. exit:        equ -144
  569. loadseg:    equ -150
  570. unloadseg:    equ -156
  571. getpacket:    equ -162
  572. queupacket:    equ -168
  573. deviceproc:    equ -174
  574. setcomment:    equ -180
  575. setprotection:    equ -186
  576. datestamp:    equ -192
  577. delay:        equ -198
  578. waitforchar:    equ -204
  579. parentdir:    equ -210
  580. IsInteractive:    equ -216
  581. Execute:    equ -222
  582.  
  583. AbsExecBase:    equ 4
  584. forbid        equ -132
  585. permit        equ -138
  586. allocmem:    equ -198
  587. freemem:    equ -210
  588. getmsg:        equ -372
  589. replymsg:    equ -378
  590. waitport:    equ -384
  591. closelibrary:    equ -414
  592. opendevice:    equ -444
  593. closedevice:    equ -450
  594. doio:        equ -456
  595. oldopenlibrary    equ -408
  596. openlibrary:    equ -552
  597.  
  598.